package com.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.vo.po.Book;
import com.vo.req.CategoryDTO;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * @author 42
 * @date 2025/6/5
 * @Description
 */
public interface BookMapper extends BaseMapper<Book> {
    @Select("select category_id AS categoryId,count(*) AS `value` from book group by category_id")
    List<CategoryDTO> getCategoryData();
    @Select({
            "SELECT",
            "CASE ",
            "WHEN price >= 0 AND price <= 50 THEN '0-50'",
            "WHEN price > 50 AND price <= 100 THEN '50-100'",
            "WHEN price > 100 AND price <= 200 THEN '100-200'",
            "WHEN price > 200 AND price <= 500 THEN '200-500'",
            "ELSE '500+'", // 新增分支
            "END AS price_range,",
            "COUNT(*) AS count",
            "FROM book",
            "GROUP BY",
            "CASE ",
            "WHEN price >= 0 AND price <= 50 THEN '0-50'",
            "WHEN price > 50 AND price <= 100 THEN '50-100'",
            "WHEN price > 100 AND price <= 200 THEN '100-200'",
            "WHEN price > 200 AND price <= 500 THEN '200-500'",
            "ELSE '500+'", // 新增分支
            "END"
    })
    List<Map<String, Object>> countBooksByPriceRange();
}
